<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/templates/templateListar.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

	<ui:define name="conteudo">
		<ui:param name="actionBean" value="#{pagamentoMB}" />
		<h:form id="frm">

			<p:hotkey bind="esc"
				handler="document.getElementById('frmTab:btnCancelar').click()" />

		</h:form>

		<h:form id="frmTab">
			<h:panelGrid columns="2">
				<p:outputLabel value="Status:" for="st" />
				<p:selectOneMenu id="st" filterMatchMode="contains" filter="true"
					value="#{pagamentoMB.status}" style="width:250px;">
					<f:selectItems value="#{pagamentoMB.listaStatus}" var="pag"
						itemLabel="#{pag.descricao}" itemValue="#{pag}"></f:selectItems>
					<p:ajax event="change" listener="#{pagamentoMB.buscar}"
						update="tabela"></p:ajax>
				</p:selectOneMenu>
				
				<p:outputLabel value="Tipo Pagamento:" for="tipopmt" />
				<p:selectOneMenu id="tipopmt" filterMatchMode="contains" filter="true"
					value="#{pagamentoMB.tipoPagamento}" style="width:250px;">
					<f:selectItems value="#{pagamentoMB.listaTipoPagamento}" var="pag"
						itemLabel="#{pag.descricao}" itemValue="#{pag}"></f:selectItems>
					<p:ajax event="change" listener="#{pagamentoMB.buscar}"
						update="tabela"></p:ajax>
				</p:selectOneMenu>
			</h:panelGrid>
			<p:commandButton id="btnCancelar" action="#{pagamentoMB.sair}"
				style="display:none" immediate="true" value="cancelar" />
			<p:commandButton actionListener="#{pagamentoMB.abrirModal}"
				title="Incluir" update=":frmDialogPagamento" value="Novo Registro"
				style="float:left" icon="ui-icon-disk" ajax="true"
				oncomplete="dialogCadastroPagamento.show()">
				<f:param name="modooperacao" value="INCLUIR" />
			</p:commandButton>
			<p:dataTable id="tabela" var="item" value="#{pagamentoMB.lista}"
				paginator="true" rows="10" emptyMessage="Não há registros"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				currentPageReportTemplate="(Página: {currentPage}/{totalPages})"
				rowsPerPageTemplate="10,15,25,50,100" paginatorPosition="bottom"
				selectionMode="single" rowKey="#{item.codigo}">
				<f:facet name="header">Pagamentos
				
				</f:facet>
				<p:column headerText="Código" sortBy="#{item.codigo}">
					<h:outputText value="#{item.codigo}" />
				</p:column>
				<p:column headerText="Data" sortBy="#{item.data}">
					<h:outputText value="#{item.data}">
						<f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT-3" />
					</h:outputText>
				</p:column>
				<p:column headerText="Cliente"
					filterBy="#{item.cliente.dadosCadastro.nome}"
					filterMatchMode="contains"
					sortBy="#{item.cliente.dadosCadastro.nome}">

					<h:outputText value="#{item.cliente.dadosCadastro.nome}" />

				</p:column>
				<p:column headerText="Tipo" sortBy="#{item.tipoPagamento.descricao}">

					<h:outputText value="#{item.tipoPagamento.descricao}" />

				</p:column>

				<p:column headerText="Status"
					sortBy="#{item.statusPagamento.descricao}">

					<h:outputText value="#{item.statusPagamento.descricao}" />

				</p:column>

				<p:column headerText="Ações" style="text-align:center">

					<p:commandButton title="Alterar" icon="ui-icon-pencil"
						styleClass="styleBotao" actionListener="#{pagamentoMB.abrirModal}"
						update=":dialogCadastro,:frmDialogPagamento,:mensagem" ajax="true"
						>

						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{pagamentoMB.pagamentoSelecionado}" />
						<f:param name="modooperacao" value="ALTERAR" />
					</p:commandButton>

					<p:commandButton actionListener="#{pagamentoMB.abrirModal}"
						styleClass="styleBotao" title="Consultar"
						update=":dialogCadastro,:frmDialogPagamento" ajax="true"
						oncomplete="dialogCadastroPagamento.show()" icon="ui-icon-search">

						<f:setPropertyActionListener value="#{item.clone()}"
							target="#{pagamentoMB.pagamentoSelecionado}" />
						<f:param name="modooperacao" value="CONSULTAR" />
					</p:commandButton>

					<p:commandButton title="Excluir" update=":Excluir"
						oncomplete="confirmation.show()" styleClass="styleRed"
						icon="ui-icon-close">
						<f:setPropertyActionListener
							target="#{pagamentoMB.pagamentoSelecionado}"
							value="#{item.clone()}" />
					</p:commandButton>

				</p:column>

				<f:facet name="footer">
					<p:outputLabel value="Total de " />
					<p:outputLabel value="#{fn:length(pagamentoMB.lista)} registro(s)" />

				</f:facet>

			</p:dataTable>


		</h:form>

		<ui:include src="dialogCadastroPagamento.xhtml" />
		<ui:include src="/includes/confirmacaoExcluir.xhtml" />
	</ui:define>
</ui:composition>

